/******************************************************************************
 * 
 * Announce: CSharpKit, Basic algorithms, components and definitions.
 *           Copyright (C) ShenYongchen.
 *           All rights reserved.
 *   Author: 申永辰.郑州 (shenyczz@163.com)
 *  WebSite: http://gitee.com/shenyczz/csharp_csk
 *
 * THIS CODE IS LICENSED UNDER THE MIT LICENSE (MIT).
 * THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF 
 * ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
 * IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
 * PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
 * 
******************************************************************************/
using System;
using System.Runtime.InteropServices;

namespace CSharpKit.Native.ECCODES
{
    // ??
    public readonly struct code_handle : IComparable, IComparable<code_handle>, IEquatable<code_handle>
    {
        public code_handle(int value)
        {
            _value = (IntPtr)value;
        }
        public code_handle(long value)
        {
            _value = (IntPtr)value;
        }
        public code_handle(IntPtr value)
        {
            _value = (IntPtr)value;
        }

        readonly IntPtr _value = IntPtr.Zero;

        // public static readonly code_handle Zero = IntPtr.Zero;

        #region CompareTo

        public int CompareTo(code_handle other)
        {
            throw new NotImplementedException();
        }
        int IComparable.CompareTo(object obj)
        {
            return CompareTo((code_handle)obj);
        }

        #endregion


        public override bool Equals(object obj)
        {
            return Equals((code_handle)obj);
        }

        public override int GetHashCode()
        {
            return base.GetHashCode() ^ _value.GetHashCode();
        }

        public bool Equals(code_handle other)
        {
            return this._value == other._value;
        }

        public static Boolean operator ==(code_handle lhs, code_handle rhs)
        {
            return lhs.Equals(rhs);
        }
        public static Boolean operator !=(code_handle lhs, code_handle rhs)
        {
            return !lhs.Equals(rhs);
        }

        public static implicit operator code_handle(IntPtr p)
        {
            return (code_handle)p;
        }

        public static implicit operator IntPtr(code_handle h)
        {
            return (IntPtr)h;
        }

        public override string ToString()
        {
            return _value.ToString();
        }

        // {{END}}
    }

}
